/**
 * 
 */
package evance.server.common.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import evance.data.model.entity.EvLoginInfo;

/**
 * @author BaoVuong
 *
 */
public class AuthenticationToken extends UsernamePasswordAuthenticationToken {

	private static final long serialVersionUID = 1;

	private LoginInfoDTO loginInfo;
	
	public EvLoginInfo getEvLoginInfo(){
		return ((CurrentUserDetails)getDetails()).getEvLoginInfo();
	}
	/**
	 * @return the loginInfo
	 */
	public LoginInfoDTO getLoginInfo() {
		return loginInfo;
	}

	/**
	 * @param loginInfo the loginInfo to set
	 */
	public void setLoginInfo(LoginInfoDTO loginInfo) {
		this.loginInfo = loginInfo;
	}

	public AuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
		super(principal, credentials, authorities);
	}

	public AuthenticationToken(Object principal, Object credentials) {
		super(principal, credentials);
	}

	public AuthenticationToken(Object principal, Object credentials, Object otherInfo) {
		super(principal, credentials);
		this.loginInfo = (LoginInfoDTO) otherInfo;
	}

	public String[] getRoles() {
		List<String> roles = new ArrayList<String>();
		for (GrantedAuthority role : getAuthorities()) {
			roles.add(role.getAuthority());
		}
		return roles.toArray(new String[roles.size()]);
	}

}

class LoginInfoDTO {

}
